package com.exartisan.network;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.exartisan.datamanager.UserAnswerDataHolder;
import com.loopj.android.http.RequestParams;

public class NewParamBuilder {

	public NewParamBuilder() {
		
	}
	
	public static RequestParams BuildParams(String data){
		RequestParams params = new RequestParams();
		params.put(NetworkUtility.DATA, data);
		return params;
	}
	
	public static String BuildTopEventData(){
		JSONObject data = new JSONObject();
		try {
			data.put(NetworkUtility.HANDLE, NetworkUtility.TOP_EVENT);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return data.toString();
	}
	
	public static String BuildNewEventData(){
		JSONObject data = new JSONObject();
		try {
			data.put(NetworkUtility.HANDLE, NetworkUtility.NEW_EVENT);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return data.toString();
	}
	
	public static String BuildGalleryInfoData(){
		JSONObject data = new JSONObject();
		try {
			data.put(NetworkUtility.HANDLE, NetworkUtility.GALLERY_INFO);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return data.toString();
	}
	
	public static String BuildDetailGalleryData(int parentType, int parrentID){
		JSONObject data = new JSONObject();
		try {
			data.put(NetworkUtility.HANDLE, NetworkUtility.HANDLE_DETAIL_GALLERY);
			data.put(NetworkUtility.PARENT_TYPE, parentType);
			data.put(NetworkUtility.PARENT_ID, parrentID);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return data.toString();
	}
	
	public static String BuildDetailEventData(long id){
		JSONObject data = new JSONObject();
		try {
			data.put(NetworkUtility.HANDLE, NewNetworkUtility.HANDLE_DETAIL_EVENT);
			data.put(NetworkUtility.EVENTID, id);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return data.toString();
	}
	
	public static String BuildCategoryData(){
		JSONObject data = new JSONObject();
		try {
			data.put(NetworkUtility.HANDLE, NetworkUtility.HANDLE_CATEGORY);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return data.toString();
	}
	
	public static String BuildEventData(int page){
		JSONObject data = new JSONObject();
		try {
			data.put(NetworkUtility.HANDLE, NetworkUtility.HANDLE_EVENT);
			data.put(NewNetworkUtility.PAGE, page);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return data.toString();
	}
	
	public static String BuildPostData(int page){
		JSONObject data = new JSONObject();
		try {
			data.put(NetworkUtility.HANDLE, NetworkUtility.HANDLE_POST);
			data.put(NewNetworkUtility.PAGE, page);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return data.toString();
	}
	
	public static String BuildDetailPostData(int id){
		JSONObject data = new JSONObject();
		try {
			data.put(NetworkUtility.HANDLE, NewNetworkUtility.HANDLE_DETAIL_POST);
			data.put(NetworkUtility.POST_ID, id);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return data.toString();
	}
	
	public static String BuildAlbumData(){
		JSONObject data = new JSONObject();
		try {
			data.put(NetworkUtility.HANDLE, "on_get_medias");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return data.toString();
	}
	
	public static String BuildDetailAlbumData(int id){
		JSONObject data = new JSONObject();
		try {
			data.put(NetworkUtility.HANDLE, "on_get_mediadetail");
			data.put("MediaID", id);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return data.toString();
	}
	
	public static String BuildDetailMediaData(int id){
		JSONObject data = new JSONObject();
		try {
			data.put(NetworkUtility.HANDLE, NewNetworkUtility.HANDLE_DETAIL_MEDIA);
			data.put("MediaID", id);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return data.toString();
	}
	
	public static String BuildCategoryForumData(){
		JSONObject data = new JSONObject();
		try {
			data.put(NetworkUtility.HANDLE, NetworkUtility.HANDLE_CATEGORY_FORUM);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return data.toString();
	}
	
	public static String BuildSurveyData(int eventID){
		JSONObject data = new JSONObject();
		try {
			data.put(NetworkUtility.HANDLE, NetworkUtility.HANDLE_SURVEY);
			data.put(NetworkUtility.EVENTID, eventID);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return data.toString();
	}
	
	public static String BuildSurveyContentData(int surveyID){
		JSONObject data = new JSONObject();
		try {
			data.put(NetworkUtility.HANDLE, NetworkUtility.HANDLE_QUESTION);
			data.put(NetworkUtility.SURVEY_ID, surveyID);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return data.toString();
	}
	
	public static String BuildSubmit(String userID, String contestID, ArrayList<UserAnswerDataHolder> userAnswerData ){
		JSONObject data = new JSONObject();
		try {
			data.put(NetworkUtility.HANDLE, "submit_contest");
			data.put("user_id", userID);
			data.put("contest_id", contestID);
			JSONArray jsonData = new JSONArray();
			for (int i = 0; i < userAnswerData.size(); i++) {
				JSONObject jsonElement = new JSONObject();
				jsonElement.put("QuestionID", userAnswerData.get(i).getQuestionID());
				jsonElement.put("AnswerID", userAnswerData.get(i).getAnswerID());
				jsonElement.put("AnswerType", userAnswerData.get(i).getAnswerType());
				jsonElement.put("AnswerText", userAnswerData.get(i).getAnswerText());
				jsonElement.put("Status", userAnswerData.get(i).getStatus());
				jsonData.put(jsonElement);
			}
			data.put("Data", jsonData);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return data.toString();
	}
	
	public static String BuildEventGallery(long id){
		JSONObject data = new JSONObject();
		try {
			data.put(NetworkUtility.HANDLE, "on_get_eventmedia");
			data.put("EventID", id);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return data.toString();
	}
}
	
	